package com.health.controller;

import com.health.constant.ResultCodeConstant;
import com.health.pojo.domain.DailyRecordDO;
import com.health.pojo.domain.HealthIndicatorDO;
import com.health.pojo.dto.CreateGroup;
import com.health.pojo.dto.DailyRecordDTO;
import com.health.pojo.dto.DeleteGroup;
import com.health.pojo.dto.HealthIndicatorDTO;
import com.health.pojo.dto.RestResult;
import com.health.pojo.dto.UpdateGroup;
import com.health.pojo.query.QueryGroup;
import com.health.pojo.query.UserQuery;
import com.health.pojo.vo.PageResult;
import com.health.service.HealthService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import java.lang.Boolean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

/**
 * 健康数据管理
 *
 * @author WUYU_MIN
 * @date 2025-04-29 23:51:18
 */
@Tag(name = "健康数据管理")
@RequestMapping("health")
@RestController
public class HealthController {

    @Autowired
    private HealthService healthService;

    /**
     * 新增健康指标
     *
     * @param healthIndicatorDTO 健康指标DTO
     * @return
     */
    @RequestMapping(value = "/addIndicator", method = RequestMethod.POST)
    @Operation(summary = "新增健康指标")
    @ResponseBody
    public RestResult<Boolean> addHealthIndicator(@RequestBody @Validated(CreateGroup.class) HealthIndicatorDTO healthIndicatorDTO) {
        Boolean result = healthService.addHealthIndicator(healthIndicatorDTO);
        return new RestResult<>(ResultCodeConstant.CODE_000000, ResultCodeConstant.CODE_000000_MSG, result);
    }

    /**
     * 删除健康指标
     *
     * @param healthIndicatorDTO 健康指标DTO
     * @return
     */
    @RequestMapping(value = "/deleteIndicator", method = RequestMethod.DELETE)
    @Operation(summary = "删除健康指标")
    @ResponseBody
    public RestResult<Boolean> deleteHealthIndicator(@RequestBody @Validated(DeleteGroup.class) HealthIndicatorDTO healthIndicatorDTO) {
        Boolean result = healthService.deleteHealthIndicator(healthIndicatorDTO);
        return new RestResult<>(ResultCodeConstant.CODE_000000, ResultCodeConstant.CODE_000000_MSG, result);
    }

    /**
     * 修改健康指标
     *
     * @param healthIndicatorDTO 健康指标DTO
     * @return
     */
    @RequestMapping(value = "/updateIndicator", method = RequestMethod.PUT)
    @Operation(summary = "修改健康指标")
    @ResponseBody
    public RestResult<Boolean> updateHealthIndicator(@RequestBody @Validated(UpdateGroup.class) HealthIndicatorDTO healthIndicatorDTO) {
        Boolean result = healthService.updateHealthIndicator(healthIndicatorDTO);
        return new RestResult<>(ResultCodeConstant.CODE_000000, ResultCodeConstant.CODE_000000_MSG, result);
    }

    /**
     * 查询健康指标
     *
     * @param userQuery 用户查询信息
     * @return
     */
    @RequestMapping(value = "/queryIndicator", method = RequestMethod.POST)
    @Operation(summary = "查询健康指标")
    public RestResult<PageResult<HealthIndicatorDO>> queryHealthIndicator(@RequestBody @Validated(QueryGroup.class) UserQuery userQuery) {
        PageResult<HealthIndicatorDO> result = healthService.queryHealthIndicator(userQuery);
        return new RestResult<>(ResultCodeConstant.CODE_000000, ResultCodeConstant.CODE_000000_MSG, result);
    }

    /************************************************************************************************************************/

    /**
     * 新增日常记录
     *
     * @param dailyRecordDTO 日常记录DTO
     * @return
     */
    @RequestMapping(value = "/addRecord", method = RequestMethod.POST)
    @Operation(summary = "新增日常记录")
    @ResponseBody
    public RestResult<Boolean> addDailyRecord(@RequestBody @Validated(CreateGroup.class) DailyRecordDTO dailyRecordDTO) {
        Boolean result = healthService.addDailyRecord(dailyRecordDTO);
        return new RestResult<>(ResultCodeConstant.CODE_000000, ResultCodeConstant.CODE_000000_MSG, result);
    }

    /**
     * 删除日常记录
     *
     * @param dailyRecordDTO 日常记录DTO
     * @return
     */
    @RequestMapping(value = "/deleteRecord", method = RequestMethod.DELETE)
    @Operation(summary = "删除日常记录")
    @ResponseBody
    public RestResult<Boolean> deleteDailyRecord(@RequestBody @Validated(DeleteGroup.class) DailyRecordDTO dailyRecordDTO) {
        Boolean result = healthService.deleteDailyRecord(dailyRecordDTO);
        return new RestResult<>(ResultCodeConstant.CODE_000000, ResultCodeConstant.CODE_000000_MSG, result);
    }

    /**
     * 修改日常记录
     *
     * @param dailyRecordDTO 日常记录DTO
     * @return
     */
    @RequestMapping(value = "/updateRecord", method = RequestMethod.PUT)
    @Operation(summary = "修改日常记录")
    @ResponseBody
    public RestResult<Boolean> updateDailyRecord(@RequestBody @Validated(UpdateGroup.class) DailyRecordDTO dailyRecordDTO) {
        Boolean result = healthService.updateDailyRecord(dailyRecordDTO);
        return new RestResult<>(ResultCodeConstant.CODE_000000, ResultCodeConstant.CODE_000000_MSG, result);
    }

    /**
     * 查询日常记录
     *
     * @param userQuery 用户查询信息
     * @return
     */
    @RequestMapping(value = "/queryRecord", method = RequestMethod.POST)
    @Operation(summary = "查询日常记录")
    public RestResult<PageResult<DailyRecordDO>> queryDailyRecord(@RequestBody @Validated(QueryGroup.class) UserQuery userQuery) {
        System.out.println(userQuery);
        PageResult<DailyRecordDO> result = healthService.queryDailyRecord(userQuery);
        System.out.println(result);
        return new RestResult<>(ResultCodeConstant.CODE_000000, ResultCodeConstant.CODE_000000_MSG, result);
    }


}
